import { EXPORT_FILE_URL } from '../enum/exportFileUrl.js'
import { objectToUrlParams } from './objectFormat.js'
import cookies from '../store/cookie.js'


/**
 *  导出-excle表
 *  @param  queryForm 查询条件
 * @param api
 */
export const useExport = (queryForm, api) => {
  // queryForm['token'] = getToken()
  if (import.meta.env.PROD) {
    try {
      navigator.serviceWorker.getRegistrations().then((registrations) => {
        for (const registration of registrations) {
          registration.unregister()
        }
      })
    } catch (e) {
      //   todo
    }
    window.open(`${location.origin}${api}?${objectToUrlParams({...queryForm, token: cookies.getToken()})}`)
    // window.open(`http://${location.host}/api/sczx/assess/evaStuReport/filterExport?${objectToUrlParams(queryForm)}`)
  }
  if (import.meta.env.DEV) {
    window.open(`http://47.111.140.195:9000${api}?${objectToUrlParams({...queryForm, token: cookies.getToken()})}`)
  }
}
